package com.echo.week;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @Author echo
 * @Description Future 案例
 * @Date 2023/10/22.
 * @Version 1.0
 */
public class DemoFuture {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        Future<Integer> future = executorService.submit(new CallableTask());

        try {
            System.out.println(future.get());
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
        executorService.shutdownNow();
    }
    static  class CallableTask implements Callable<Integer>{

        @Override
        public Integer call() throws Exception {
            Thread.sleep(2000);
            return new Random().nextInt();
        }
    }
}
